package com.zzxz.practicaltrainingsys.controller;

import com.zzxz.practicaltrainingsys.common.Result;
import com.zzxz.practicaltrainingsys.service.GroupVoService;
import com.zzxz.practicaltrainingsys.vo.GroupVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/group")
@CrossOrigin
public class GroupVoController {
    @Autowired
    private GroupVoService groupVoService;

    @GetMapping("/project")
    public Result<List<GroupVo>> getGroupsByProject(
            @RequestParam Integer teacherId,
            @RequestParam Integer projectId) {

        // 参数验证
        if (teacherId == null || projectId == null) {
            return Result.fail("教师ID和项目ID不能为空");
        }

        try {
            List<GroupVo> groups = groupVoService.getGroupsByTeacherAndProject(teacherId, projectId);

            if (groups.isEmpty()) {
                return Result.success(groups);
            }

            return Result.success(groups);
        } catch (Exception e) {
            // 记录日志
            e.printStackTrace();
            return Result.fail("获取小组信息失败: " + e.getMessage());
        }
    }
}
